package com.huluobo.a2203kotlinshopping.order

import androidx.lifecycle.MutableLiveData
import com.google.gson.Gson
import com.huluobo.base.bean.ChangeCartBeanResult
import com.huluobo.base.bean.OrderBean
import com.huluobo.base.net.Const
import com.huluobo.base.viewModel.BaseViewModel
import okhttp3.MediaType
import okhttp3.RequestBody

/**
 *  Created by LC on 2024/7/1.
 */
class PayViewModel : BaseViewModel<PayRepo>() {
    val queryOrderListSuccess = MutableLiveData<List<OrderBean>>()
    val queryOrderListFailed = MutableLiveData<String>()

    val deleteCartSuccess = MutableLiveData<ChangeCartBeanResult>()
    val deleteCartFailed = MutableLiveData<String>()

    fun deleteCart(ids: String) {
        val map = mutableMapOf<String, String>()
        map[Const.PARAM_IDS] = ids
        val json = Gson().toJson(map)
        val body = RequestBody.create(MediaType.parse(Const.MEDIA_TYPE), json)
        repo.deleteCart(body, deleteCartSuccess, deleteCartFailed)
    }

    fun queryOrderList() {
        repo.queryOrderList(queryOrderListSuccess, queryOrderListFailed)
    }

    override fun createRepo(): PayRepo = PayRepo()
}